package com.lan.model;

import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

public class Tv<T> {

    private Type type;

    private T value;

    public Tv(Type type, T value) {
        this.type = type;
        this.value = value;
    }

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public T getValue() {
        return value;
    }

    public void setValue(T value) {
        this.value = value;
    }


    @Override
    public String toString() {
        return "Tv{" +
                "type=" + type +
                ", value=" + value +
                '}';
    }

    public static String toString(List<Tv> list, int val) {
        AtomicInteger index = new AtomicInteger(0);
        List ss = list.stream().filter(i -> index.getAndIncrement() < val).map(v -> v.getValue()).collect(Collectors.toList());
        return ss.toString();
    }


    public static String toString(List<Tv> list, String sep) {
        List ss = list.stream().map(v -> v.getValue()).collect(Collectors.toList());
        return StringUtils.join(ss, sep);
    }


}
